using System;
using UnityEngine;
using Yoozoo.Gta.Common;
using Yoozoo.UI.YGUI;

namespace Yoozoo.Gameplay
{
    /// <summary>
    /// 同步lua层枚举 L_Enum.PlayerHankBookType
    /// </summary>
    public enum PlayerHankBookType
    {
        None                        = 0, // 不打开界面，有些按钮在界面不同状态下会打开不同的界面，所以需要单独做逻辑。
        PLAYER_HAND_BOOK            = 1, // 玩家手册
        ALLIANCE_HAND_BOOK          = 2, // 联盟手册
    }
    
    public class PlayerHandBookGotoKey : MonoBehaviour
    {
        [Tooltip("要打开的手册类型")]
        [SerializeField]
        private PlayerHankBookType handBookType;

        [Tooltip("要打开的页签按钮，不填则默认打开第一个页签")]
        [SerializeField]
        private int handBookMainId;

        [Tooltip("要打开的子页签按钮，不填则默认打开第一个子页签")]
        [SerializeField]
        private int handBookSubId;
        
        private void Start()
        {
            var btn = GetComponent<YButton>();
            if (btn)
            {
                btn.onClick.AddListener(OnBtnClicked);
            }
        }

        private void OnBtnClicked()
        {
            if (handBookType == PlayerHankBookType.None)
            {
                return;
            }
            ResidentHandler.Inst.GetFunction("CityLuaFunction.openPlayerHandBookWindow").Action((int) handBookType, handBookMainId, handBookSubId);
        }
    }
}
